package tsli.acm.ctrl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tsli.acm.database.Database;

/**
 * Servlet implementation class ACM11021Srvl
 */
@WebServlet("/ACM11021Srvl")
public class ACM11021Srvl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ACM11021Srvl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		getData(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		getData(request, response);
	}
	
	public void getData(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/JSON");
		
		System.out.println("Come to ACM11021Srvl");
		String processType = request.getParameter("processType");
		System.out.println("ProcessType : "+processType);
		String closYm = request.getParameter("closYm");
		System.out.println("ClosYm : "+closYm);
		PrintWriter voOut = response.getWriter();
		
		if(processType.equals("calculateAlBonus")||processType=="calculateAlBonus"){
			boolean result;
			Database db = new Database();
			 ALComponentAPIMethod componentAPIMethod  = new ALComponentAPIMethod();
			 result = componentAPIMethod.calculateAL(closYm);
			 db.close();
			 System.out.println("calculateAlBonus Done");
			 response.getWriter().write("Process Bonus AL success");
			 }
		
		} 
		
	}


